﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;

namespace tutFuelCellGame
{
    public class SoundManager: GameComponent
    {
        // XACT project variables
        private AudioEngine audioEngine;
        private WaveBank waveBank;
        private SoundBank soundBank;

        public SoundManager(Game game) : base(game)
        {
        }

        public override void Initialize()
        {
            base.Initialize();
        }

        public void LoadAudioContent()
        {
            audioEngine = new AudioEngine("Content/Sounds/FuelCellSounds.xgs");
            waveBank = new WaveBank(audioEngine, "Content/Sounds/Wave Bank.xwb");
            soundBank = new SoundBank(audioEngine, "Content/Sounds/Sound Bank.xsb");
        }

        Cue music = null;

        public void ResetSounds()
        {
            music.Stop(AudioStopOptions.Immediate);
            music = null;
        }

        public void OnFuelCellFound()
        {
            soundBank.PlayCue("FuelFound");
        }

        public void PlayGameLostSound()
        {
            soundBank.PlayCue("GameLost");
        }

        public void StartMusic()
        {
            if (music == null)
                music = soundBank.GetCue("Background");
            if (GameConstants.MusicOn && !music.IsPlaying)
                music.Play();
        }

        public void StopMusic()
        {
            music.Stop(AudioStopOptions.AsAuthored);
        }


    }
}
